<?php

/**
 * Description of PersonPersonClass
 *
 * @author adhamhelal
 */
class OrgOrgPanel extends Qpanel {
    protected $mctOrg;

    //Controls
    // Controls for 's Data Fields
    protected $txtName;
    protected $lstType;
    protected $txtOracleLink;
    protected $strTemplate;

    public function __construct($objParentObject, $mctOrg, $strControlId = null) {
        // Call the Parent
        try {
            parent::__construct($objParentObject, $strControlId);
        } catch (QCallerException $objExc) {
            $objExc->IncrementOffset();
            throw $objExc;
        }

        // Setup Template
        $this->strTemplate = __DOCROOT__.__PERSON__ .  '/tpl/qpanel.tpl.php';
        // Set the Person Meta Conrol
        $this->mctOrg = $mctOrg;

        // Call MetaControl's methods to create qcontrols based on ComSchool's data fields
        $this->txtName = $this->mctOrg->txtName_Create();
        $this->txtName->SetParentControl($this);

        $this->txtOracleLink = $this->mctOrg->txtOracleLink_Create();
        $this->txtOracleLink->SetParentControl($this);

        $this->lstType = $this->mctOrg->lstType_Create();
        $this->lstType->SetParentControl($this);
    }

    public function Validate() {
        $Error = false;
        if ($this->txtName->Text == "") {
            $this->txtName->Warning=QApplication::Translate("Required");
            $Error=true;
        }
        
        if (strlen($this->txtOracleLink->Text) > 0){
            $OrgDup = Org::LoadByOracleLink($this->txtOracleLink->Text);
            $OrgCurrent = $this->mctOrg->__get("Org");
            if (  $OrgDup && ($OrgDup->Id <> $OrgCurrent->Id) ){
                $this->txtOracleLink->Warning=QApplication::Translate("Duplicate Number");
                $Error=true;
            }
        }

        $blnFocused = false;
        foreach ($this->GetChildControls()  as $objControl) {
            if ( !is_null($objControl->Warning) ) {
                if (!$blnFocused) {
                    $objControl->Focus();
                    $blnFocused = true;
                }
                $objControl->Blink();
            }
        }

        return $Error;
    }



}
?>

